<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询（media queries）功能 -->
    <!-- 警告：通过 file:// 协议（就是直接将 html 页面拖拽到浏览器中）访问页面时 Respond.js 不起作用 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
    <![endif]-->

    <script src="js/jquery-2.1.1.min.js"></script>
    <script src="js/zhangyue6.4.js"></script>

    <!--引入bootstrap文件-->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <!--引入index.css-->
    <link rel="stylesheet" href="css/index.css">
    <!--引入ico小图标 -->
    <link rel="shortcut icon" href="favicon.ico"  type="image/x-icon"/>
    <title>云智教育</title>
</head>
<body>
    <header class="container">
        <div class="row">
            <div class="col-md-5">
                <div class="fixed">
                    <!--左侧头部-->
                    <ul class="nav">
                        <li><a href="index.html">首页</a></li>
                        <li><a href="class_list.html">课程</a></li>
                        <!--<li><a href="#">职业规划</a></li>-->
                        <li><a onclick="_sousuo()" class="glyphicon glyphicon-search"></a></li>
                    </ul>
                    <!--左侧中间-->
                    <div class="middle">
                            <h3 class="word">云智教育，学有所成</h3>
                                <span class="glyphicon glyphicon-education"></span>
                            <footer id="footer">

                            </footer>
                    </div>
                </div>
            </div>
            <article class="col-md-7">
                <div class="box" >
                    <div class="box-hd">
                        <h3>课程详情</h3>
                    </div>
                    <div class="box-bd clearfix" id="xiangqing">

                    </div>
                </div>
                <!--box end -->
            </article>
        </div>
    </header>
</body>
<script src="js/html.js"></script>
<script>

    const kid = window.location.href.split('kid=')[1];
    if(!kid || kid==""){
        window.location.href='index.html';
    }

    if(!mydata.get('id') || mydata.get('id')==""){
        alert('请先登录');
        window.location.href='landing.html';
    }

    shuju.set('kid',kid);
    shuju.set('uid',mydata.get('id'));
    shuju.set('method','detail');
    shuju.getshuju('kecheng',{
        success:function(data){
            let obj = data.data;
            document.getElementById('xiangqing').innerHTML=`
              <h3>${obj.name}</h3>
    <p>${obj.addtime}</p>

    <article>

    课程内容：${obj.neirong}<br>
    课程地点：${obj.didian}<br>
    课程时间：${obj.shijian}<br>
    课程周期：${obj.zhouqi}<br>
    老师姓名：${obj.teacher}

    </article>
    <img style="max-width: 40vw" src='${obj.fengmian}'>
    <div style="display: flex">
    <a style="margin-right: 20px" onclick="_xuanke(this)" class="btn btn-${obj.xuanke?'warning':'info'}">${obj.xuanke?'已':''}选课</a><br>
    <a onclick="_shoucang(this)" class="btn btn-${obj.shoucang?'warning':'info'}">${obj.shoucang?'已':''}收藏</a>
    </div>

                `;

        },
        error:function(e){
            alert('网络错误');
        }
    });


    const _xuanke=function(obj){
        let value = obj.innerHTML;
        shuju.set('uid',mydata.get('id'));
        shuju.set('kid',kid);
        shuju.set('method',(value=='选课'?'add':'delete')+'xuanke');
        shuju.getshuju('kecheng',{
            success:function(data){
                if(data.code==200){
                    alert('操作成功');
                    obj.innerHTML=value=='已选课'?'选课':'已选课';
                    obj.setAttribute('class',value=='已选课'?'btn btn-info':'btn btn-warning');
                }else{
                    alert('请检查网络');
                }
            },
            error:function(e){
                alert('请检查网络');
            }
        })
    };

    const _shoucang=function(obj){
        let value = obj.innerHTML;
        shuju.set('uid',mydata.get('id'));
        shuju.set('kid',kid);
        shuju.set('method',(value=='收藏'?'add':'delete')+'shoucang');
        shuju.getshuju('kecheng',{
            success:function(data){
                if(data.code==200){
                    alert('操作成功');
                    obj.innerHTML=value=='已收藏'?'收藏':'已收藏';
                    obj.setAttribute('class',value=='已收藏'?'btn btn-info':'btn btn-warning');
                }else{
                    alert('请检查网络');
                }
            },
            error:function(e){
                alert('请检查网络');
            }
        })
    }





</script>
</html>